<template>
  <div class="baobaotuan">
    <header>
      <transition name="fade" mode="out-in">
        <keep-alive>
          <component :is="coms[top]"></component>
        </keep-alive>
      </transition>
      <div class="nax">
        <span
          v-for="(item, index) in topArr"
          :key="index"
          @click="qiehuan(index)"
          :class="{ active: top == index }"
        >
          {{ item }}
        </span>
      </div>
    </header>
  </div>
</template>

<script>
import Goshopping from "../../components/Goshopping.vue";
import Yugao from "../../components/Yugao.vue";

export default {
  data() {
    return {
      top: 0,
      topArr: ["正在抢购", "上新预告"],
      coms: [Goshopping, Yugao],
    };
  },
  methods: {
    qiehuan(index) {
      this.top = index;
    },
  },
};
</script>

<style lang='scss' scoped>
.fade-enter {
  opacity: 0;
}
.fade-enter-active {
  transition: all 0.4s;
}
.fade-enter-to {
  opacity: 1;
}
.fade-leave {
  opacity: 1;
}
.fade-leave-active {
  transition: all 0.4s;
}
.fade-leave-to {
  opacity: 0;
}
.active {
  color: red;
}
.baobaotuan {
  width: 100%;
  height: 100%;

}
.nax {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ccc;
  background-color: pink;
  position: fixed;
  top: 0;
  line-height: 40px;

}
header {
  width: 100%;
  height: 100%;

  span {
    margin-right: 22px;
  }
}
</style>